package org.scboy.common.dynamic.node.logicNode;

import org.scboy.common.annotation.ScriptNode;
import org.scboy.common.dynamic.node.BaseNode;

import cn.hutool.json.JSONObject;

@ScriptNode(value="LOGIC_IS_NOT_NULL")
public class LogicIsNotNullNode extends BaseNode {

	@Override
	public void create(JSONObject object) {
		
	}

	@Override
	public Object run() {
		/**
		 * 测试日志
		 */
		if(this.script.isTest()) {
			this.script.appendMsg("----->开始执行："+getNodeName()+" 节点ID："+this.getId());
		}
		
		//输出流
		BaseNode runYesTo = getRunTo("yes");

		BaseNode runNoTo = getRunTo("no");
		
		Object object=getSourceData("params", true, Object.class);
		
		if(object != null) {
			
			/**
			 * 测试日志
			 */
			if(this.script.isTest()) {
				this.script.appendMsg("判断结果：存在");
				this.script.appendMsg("缓存数据：\r\n"+entityToString(this.getDataAll()));
				this.script.appendMsg("执行下个节点："+runYesTo.getNodeName()+" 节点ID："+runYesTo.getId());
			}
			
			return runYesTo.run();
		}else {
			
			/**
			 * 测试日志
			 */
			if(this.script.isTest()) {
				this.script.appendMsg("判断结果：不存在");
				this.script.appendMsg("缓存数据：\r\n"+entityToString(this.getDataAll()));
				this.script.appendMsg("执行下个节点："+runNoTo.getNodeName()+" 节点ID："+runNoTo.getId());
			}
			
			return runNoTo.run();
		}
	}
}
